package org.example.stream;
import com.alibaba.fastjson.JSON;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author: lynn
 * @Descript:
 * @date: 2023/7/1 15:22
 * @version: 1.0
 */
public class testMap {

    public static void main(String[] args) {

        List<StudentVo> studentVoList= Arrays.asList(new StudentVo("张三","女",19),
                new StudentVo("李四","女",18),
                new StudentVo("王五","女",20),
                new StudentVo("马六","男",21)
        );
        List<String> str=studentVoList.stream().map(e->e.getName().concat("-").concat(e.getSex())).collect(Collectors.toList());
        System.out.println(JSON.toJSONString(str));
        String s=studentVoList.stream().map(e->e.getName().concat("-").concat(e.getSex())).collect(Collectors.joining(","));
        System.out.println(s);

        List<StudentVo> stu18= studentVoList.stream().filter(e->e.getAge()>18).sorted((o1, o2)->o2.getAge()-o1.getAge()).collect(Collectors.toList());
        System.out.println(JSON.toJSONString(stu18));

        List<StudentVo> vo=studentVoList.stream().peek(e->e.setName(e.getName().concat("-").concat(e.getSex()))).sorted((o1,o2)->o1.getAge()-o2.getAge()).collect(Collectors.toList());
        System.out.println(JSON.toJSONString(vo));

        Map<String,List<StudentVo>> groupMap=studentVoList.stream().collect(Collectors.groupingBy(StudentVo::getSex));
        System.out.println(JSON.toJSONString(groupMap));

        Map<Integer,StudentVo> toMap= studentVoList.stream().collect(Collectors.toMap(StudentVo::getAge,o->o));
        System.out.println(JSON.toJSONString(toMap));
    }
}
